<!--
 * @Description:
 * @Author: zhaolei
 * @Date: 2023-04-21 11:27:57
-->
<template>
  <el-dialog
    title="查看内容详情"
    :visible.sync="visible"
    width="60%"
    append-to-body
  >
    <avue-form
      ref="addForm"
      v-model="form"
      :option="tableOption"
    >
      <template #topTime>
        <span>{{ form.topStartTime }} - {{ form.topEndTime }}</span>
      </template>
    </avue-form>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex';
import { tableOption } from '@/const/crud/content/detail';
import { getPetObj } from '@/api/core/content';
// import { BROADCAST_TYPE } from '@/const/type';
export default {
  name: 'Detail',
  props: {
    id: {
      type: [Object, String],
    },
    value: {
      type: Boolean,
      default: false,
    },
    typeList: {
      type: [Array],
    },
  },
  data() {
    return {
      form: {},
      loading: false,
    };
  },
  computed: {
    tableOption() {
      return tableOption(this.typeList);
    },
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
    ...mapGetters(['userInfo', 'access_token']),
  },
  watch: {
    visible(val) {
      if (val) {
        this.getDetail();
      } else {
        this.$refs['addForm'].resetFields();
      }
    },
  },
  methods: {
    async getDetail() {
      const res = await getPetObj(this.id);
      this.form = { ...res.data.data };
      if (Array.isArray(JSON.parse(this.form.files))) {
        const temp = JSON.parse(this.form.files);
        this.form.petPicture = temp.map((item) => {
          let type = 'mov';
          if (item.type === 'image') {
            type = 'jpg';
          }
          return `${item.url}?.${type}`;
        });
      }
      this.form.petList = this.form.petList.map((el) => el.id).join('，');
    },
  },
};
</script>

<style lang="scss" scoped>
.tags-item {
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid rgba(161, 216, 230, 1);
  color: rgba(161, 216, 230, 1);
  margin-right: 20px;
}
.mb-20 {
  margin-bottom: 20px;
}
.tags-title {
  width: 80px;
  text-align: right;
}
</style>
